﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using myBoard.App.Components.MagnetsStore.ViewsModels;
using System.ComponentModel;
using myBoard.App.Business;
using myBoard.Framework;

namespace myBoard.App.Model
{
    /// <summary>
    /// This class stores instances of classes that should be instanced only once in myBoard.
    /// </summary>
    public class Instances : INotifyPropertyChanged
    {
        private Configuration _currentConfiguration;

        public InstalledMagnets InstalledMagnets 
        {
            get
            {
                return SingletonFactory.GetInstance<InstalledMagnets>();
            }
        }

        public MagnetsViewModel MagnetsViewModel
        {
            get
            {
                return SingletonFactory.GetInstance<MagnetsViewModel>();
            }
        }

        public UsersViewModel UsersViewModel
        {
            get
            {
                return SingletonFactory.GetInstance<UsersViewModel>();
            }
        }

        public CategoriesViewModel CategoriesViewModel
        {
            get
            {
                return SingletonFactory.GetInstance<CategoriesViewModel>();
            }
        }

        public Configuration CurrentConfiguration 
        {
            get
            {
                if (_currentConfiguration == null)
                {
                    try
                    {
                        ConfigurationSerializer cs = new ConfigurationSerializer();
                        _currentConfiguration = cs.DeSerialize();
                    }
                    catch (Exception ex)
                    {
                        ExceptionsManager.LogException("myBoard", ex, true);                       
                    }
                }
                return _currentConfiguration;
            }
        }

        private void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
